﻿using MediatR;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using wt.wine.Application.Common.Interfaces;
using wt.wine.Application.Common.Models;

namespace wt.wine.Application.ManageDevicetable.Queries
{
    /// <summary>
    /// 缺酒补货提醒
    /// </summary>
    public class GetDeviceLessWineQueries:IRequest<Json<PaginatedList<GetDeviceLessWineDTO>>>
    {
        /// <summary>
        /// 第几页
        /// </summary>
        public int pageIndex { get; set; }
        /// <summary>
        /// 页码
        /// </summary>
        public int pageSize { get; set; }
    }

    public class GetDeviceLessWineQueriesHandler : IRequestHandler<GetDeviceLessWineQueries, Json<PaginatedList<GetDeviceLessWineDTO>>>
    {
        private readonly ICurrentUserService _icurrentUserServices;
        private readonly IDevicetableRepository _iDevicetableRepository;
        public GetDeviceLessWineQueriesHandler(ICurrentUserService icurrentUserServices, IDevicetableRepository iDevicetableRepository)
        {
            _icurrentUserServices = icurrentUserServices;
            _iDevicetableRepository = iDevicetableRepository;
        }
        public async Task<Json<PaginatedList<GetDeviceLessWineDTO>>> Handle(GetDeviceLessWineQueries request, CancellationToken cancellationToken)
        {
            int userid = _icurrentUserServices.GetUserId();
            if (request.pageIndex <= 0 || request.pageSize > 1000)
            {
                return Json<PaginatedList<GetDeviceLessWineDTO>>.Failed("参数异常");
            }
            else {
                var model = await _iDevicetableRepository.GetDeviceLessWineList(userid, request.pageIndex, request.pageSize, cancellationToken);
                return Json<PaginatedList<GetDeviceLessWineDTO>>.Success("查询成功", model);
            }
        }
    }
}
